package cn.edu.neusoft.wuguangsheng.flowerimpression.activity;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import cn.edu.neusoft.wuguangsheng.flowerimpression.R;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.SuccessBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.UserFlagBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.listener.TListener;
import cn.edu.neusoft.wuguangsheng.flowerimpression.model.CommentFKnowModel;
import cn.edu.neusoft.wuguangsheng.flowerimpression.model.GetUserFlagModel;

public class CommentFKnowActivity extends BaseActivity implements View.OnClickListener{
    ImageView commentfknow_fh;
    EditText commentfknow_content;
    Button commentfknow_btn;
    String fknowid;
    @Override
    void initView() {
        setLayout_file(R.layout.activity_comment_fknow);
        commentfknow_fh = (ImageView)findViewById(R.id.commentfknow_fh);
        commentfknow_content = (EditText)findViewById(R.id.commentfknow_content);
        commentfknow_btn = (Button)findViewById(R.id.commentfknow_btn);
        fknowid = getIntent().getStringExtra("fknowid");
    }

    @Override
    void initEvent() {
        commentfknow_fh.setOnClickListener(this);
        commentfknow_btn.setOnClickListener(this);

    }

    @Override
    void initDate() {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.commentfknow_fh:
                finish();
                break;
            case R.id.commentfknow_btn:
                final String content = commentfknow_content.getText().toString().trim();
                if (content.equals("")){
                    Toast.makeText(CommentFKnowActivity.this,"评论信息不能为空",Toast.LENGTH_SHORT).show();
                }
                else{
                   // Toast.makeText(CommentFKnowActivity.this,"评论信息不能为空",Toast.LENGTH_SHORT).show();
                    GetUserFlagModel getUserFlagModel = new GetUserFlagModel();
                    getUserFlagModel.getUserFlag(getid(), new TListener<UserFlagBean>() {
                        @Override
                        public void onResponse(UserFlagBean userFlagBean) {
                            if (userFlagBean.getUserflag().equals("2")){
                                Toast.makeText(CommentFKnowActivity.this, "当前你已被系统禁止登陆，不可评论任何文章", Toast.LENGTH_SHORT).show();
                            }
                            else if (userFlagBean.getUserflag().equals("1")){
                                Toast.makeText(CommentFKnowActivity.this, "当前你已被系统禁止评论，不可评论任何文章", Toast.LENGTH_SHORT).show();
                            }
                            else {
                                CommentFKnowModel commentFKnowModel = new CommentFKnowModel();
                                commentFKnowModel.commentFKnow(getid(),fknowid,content,successBeanTListener);
                            }
                        }
                        @Override
                        public void onFail(String msg) {
                        }
                    });

                }
                break;

        }
    }

    TListener<SuccessBean> successBeanTListener = new TListener<SuccessBean>() {
        @Override
        public void onResponse(SuccessBean successBean) {
            if (successBean.getSuccess().equals("1")){
                Toast.makeText(CommentFKnowActivity.this,"评论成功",Toast.LENGTH_SHORT).show();
                finish();
            }
            else{
                Toast.makeText(CommentFKnowActivity.this,"评论失败",Toast.LENGTH_SHORT).show();
            }

        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(CommentFKnowActivity.this,"网络错误",Toast.LENGTH_SHORT).show();
        }
    };
}
